package com.woniuxy01;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-07-25 11:46
 */
public class Test02 {
    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("zs", 11, 90);
        students[1] = new Student("ls", 13, 95);
        students[2] = new Student("ww", 12, 92);
        System.out.println("排序前");
        System.out.println(Arrays.toString(students));
        System.out.println("自定义Compartor排序:成绩降序排列");
//        //接口实现类对象
//        Comparator scoreComparatorDesc=new Comparator(){
//            @Override
//            public int compare(Object o1, Object o2) {
//                if(o1 instanceof Student && o2 instanceof Student){
//                    return (int) (((Student) o2).getScore()-((Student) o1).getScore());
//                }
//                return 0;
//            }
//        };
        Comparator xxxCompartor = new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if (o1 instanceof Student && o2 instanceof Student) {
                    return (int) (((Student) o2).getScore() - ((Student) o1).getScore());
                }
                return 0;
            }
        };
        Arrays.sort(students, xxxCompartor);

        System.out.println(Arrays.toString(students));

        System.out.println("自定义Compartor排序:成绩升序排列");
        Arrays.sort(students, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if (o1 instanceof Student && o2 instanceof Student) {
                    return (int) (((Student) o1).getScore() - ((Student) o2).getScore());
                }
                return 0;
            }
        });
        System.out.println(Arrays.toString(students));


        Arrays.sort(students, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if (o1 instanceof Student && o2 instanceof Student) {
                    return (int) (((Student) o1).getScore() - ((Student) o2).getScore());
                }
                return 0;
            }
        });
        Arrays.sort(students, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if (o1 instanceof Student && o2 instanceof Student) {
                    return (int) (((Student) o1).getScore() - ((Student) o2).getScore());
                }
                return 0;
            }
        });


//        StudentAgeDesc studentAgeDesc = new StudentAgeDesc();
//        System.out.println(studentAgeDesc.getClass());
//        System.out.println(scoreComparatorDesc.getClass());
    }

    private static void test01() {
//        Student s1 = new Student("zs",11);
//        System.out.println(s1.getName());
//        System.out.println(s1.getAge());
//
//        //匿名对象
//        System.out.println(new Student("ls",12).getAge());
//        int num = new Scanner(System.in).nextInt();
    }
}
